<template>
    <div>
        <Table highlight-row ref='table' :columns='columns' :loading='loading' :data='data' :height="520">
            <template slot-scope="{row}" slot="info">
                <Tooltip content="导医" placement="right" v-if="+row.is_guide_create===1">
                    {{ row.true_name || row.user_name }}
                    {{ row.gender_str }} {{ row.age }}
                    <Icon type="md-person" />
                </Tooltip>
                <Tooltip content="回收站" placement="right" v-if="+row.status ===-1">
                    {{ row.true_name || row.user_name }}
                    {{ row.gender_str }} {{ row.age }}
                    <Icon type="md-trash" />
                </Tooltip>
                <span v-if="+row.is_guide_create!==1&&+row.status !==-1">
                    {{ row.true_name || row.user_name }}
                    {{ row.gender_str }} {{ row.age }}
                </span>
            </template>
            <template slot-scope="{ row }" slot="channel">
                <Badge
                    v-if="row.source_name === 0"
                    status="success"
                    :text="row.source_name"
                />
                <Badge
                    v-if="row.source_name === 1"
                    status="processing"
                    :text="row.source_name"
                />
                <Badge
                    v-if="row.source_name === 2"
                    status="error"
                    :text="row.source_name"
                />
                <Badge
                    v-if="row.source_name === 3"
                    status="warning"
                    :text="row.source_name"
                />
                <span v-if="row.source_name">{{ row.source_name }}</span>
                <span v-else>{{'/'}}</span>
            </template>
            <template slot-scope="{ row }" slot="disease">
                <span v-if="row.child_diseases_name || row.diseases_name">{{
                    row.child_diseases_name || row.diseases_name
                }}</span>
                <span v-else>{{'/'}}</span>
            </template>
            <template slot-scope="{row}" slot="option">
                <a v-if="+row.is_auth===1"  @click="handleDetailPatient(row)">详细</a>
            </template>
        </Table>
        <Page
            show-total
            show-elevator
            show-sizer
            :total="total"
            :current.sync="params.page"
            :page-size="params.pageSize"
            :page-size-opts="pageOpts"
            @on-change="changepage"
            @on-page-size-change="changepageSize"
            class="ivu-mt-16"
        ></Page>
        <patient-detail ref="patientDetail" :btnShow="btnShow" @cancelDrawer="askData" @askData="askData"/>
    </div>
</template>
<script>
import patientDetail from '@/components/patientDetail';
import{searchallList}from '@/api/globalsearch.js';
export default {
  components: { patientDetail },
    data(){
        return{
            columns: [
                {
                    title: '基本信息',
                    slot: 'info',
                    minWidth: 140,
                },
                {
                    title: '手机号',
                    key: 'mobiles',
                    minWidth: 140,
                    render: (h,params) => {
                        return h('span',params.row.mobiles.length > 0 ? params.row.mobiles.join(',') : '/'); 
                    }
                },
                {
                    title: '微信号',
                    key: 'wechat_id',
                    minWidth: 140,
                    render: (h,params) => {
                        return h('span',params.row.wechat_id ? params.row.wechat_id : '/'); 
                    }
                },
                {
                    title: '备注',
                    key: 'remark',
                    ellipsis: true,
                    tooltip: true,
                    minWidth: 100,
                    render: (h,params) => {
                        return h('Ellipsis',{props:{'text':params.row.remark?params.row.remark:'/' ,'length':6,'tooltip':true}}); 
                    }
                   
                },
                {
                    title: '归属人',
                    key: 'realname',
                    minWidth: 100,
                    render: (h,params) => {
                        return h('span',params.row.realname ? params.row.realname : '/'); 
                    }
                },
                {
                    title: '病种',
                    slot: 'disease',
                    minWidth: 100,
                },
                {
                    title: '城市',
                    key: 'city_name',
                    minWidth: 100,
                    render: (h,params) => {
                        return h('span',params.row.city_name ? params.row.city_name : '/'); 
                    }
                },
                {
                    title: '来源',
                    slot: 'channel' ,
                    minWidth: 120,
                },
                {
                    title: '创建时间',
                    key: 'created_at_str',
                    minWidth: 160,
                    render: (h,params) => {
                        return h('span',params.row.created_at_str ? params.row.created_at_str : '/'); 
                    }
                },
                {
                    title: '操作',
                    slot: 'option',
                    minWidth: 80,
                },
            ],
            loading: false,
            data: [],
            btnShow: [
                {
                    name: 'patient-index-sub5',
                    flag: 'v1/patient/index/sub'
                },
                {
                    name: 'patient-index-edit-remark5',
                    flag: 'v1/patient/index/edit-remark'
                },
                {
                    name: 'v1-patient-index-update',
                    flag: 'v1/patient/index/update'
                },
                {
                    name: 'patient-callback-callback-common-list4',
                    flag: 'v1/patient/callback/callback-common-list'
                },
                {
                    name: 'patient-index-edit-tags10',
                    flag: 'v1/patient/index/edit-tags'
                },
                {
                    name: 'patient-index-edit-tags13',
                    flag: 'v1/patient/index/edit-tags'
                }
            ],
            total:0,
            pageOpts: [10, 15, 20, 30, 50],
            params:{
                page: 1,
                pageSize: 10,
            },
            keyword:''
        };
    },
    methods: {
        initial(val){
            if(val == ''){
                this.data = [];
            }else{
                this.keyword=val
                this.getsearchallList(val);
            }
           
        },
        changepage(e) {
            this.params.page = e;
            this.getsearchallList(this.keyword);
        },
        /* @函数功能: 每页数量 */
        changepageSize(e) {
            this.params.pageSize = e;
            this.getsearchallList(this.keyword);
        },
        getsearchallList(val){
            this.loading=true
            searchallList({keywords: val,...this.params}).then(res => {
                this.total = res.total;
                this.data = res.list;
                this.loading=false
            }).catch(()=>{
                this.loading=false
            });
        },
        askData(){
            //  this.$emit('askData', this.params);
        },
        handleDetailPatient (row) {
            this.$refs.patientDetail.handleOpen(row);
        },
    }
    
};
</script>